package cn.kooki.app.duobao.ui.Activity.User;

import android.support.v4.app.FragmentTransaction;
import android.view.View;

import cn.kooki.app.duobao.R;
import cn.kooki.app.duobao.base.BaseNavActivity;
import cn.kooki.app.duobao.data.bus.ShipAddressEmptyEvent;
import cn.kooki.app.duobao.data.bus.ShipAddressNotEmptyEvent;
import cn.kooki.app.duobao.ui.Activity.User.AddShipAddressActivity;
import cn.kooki.app.duobao.ui.Fragment.shipaddress.AddShopAddressFragment;
import cn.kooki.app.duobao.ui.Fragment.shipaddress.ShipAddressListFragment;

/**
 * Created by xiong on 2015/12/14.
 */
public class ShipAddressActivity extends BaseNavActivity {

    private ShipAddressListFragment listFragment;
    private AddShopAddressFragment addressFragment;

    @Override
    public void setLayoutContainerView() {
        setContainerView(R.layout.activity_ship_address_list);
    }

    @Override
    protected void afterView() {

        listFragment = new ShipAddressListFragment();
        addressFragment = new AddShopAddressFragment();
        addFragment(R.id.container, listFragment);
        addFragment(R.id.container, addressFragment);
        FragmentTransaction fragmentTransaction = getFragmentTransaction();
        fragmentTransaction.show(listFragment).hide(addressFragment).commit();
        setTitle(R.string.title_activity_ship_address_list);
        actionEdit.setText(R.string.add);
        actionEdit.setTextColor(getResources().getColor(R.color.blue));
        actionEdit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                intent(AddShipAddressActivity.class);
            }
        });

    }


    public void onEventMainThread(ShipAddressEmptyEvent event) {
        actionEdit.setVisibility(View.GONE);
        FragmentTransaction fragmentTransaction = getFragmentTransaction();
        fragmentTransaction.show(addressFragment).hide(listFragment).commitAllowingStateLoss();
    }

    public void onEventMainThread(ShipAddressNotEmptyEvent event) {
        actionEdit.setVisibility(View.VISIBLE);
        FragmentTransaction fragmentTransaction = getFragmentTransaction();
        fragmentTransaction.show(listFragment).hide(addressFragment).commitAllowingStateLoss();
    }
}
